package cn.bitkit.tools.data;

import cn.bitkit.base.util.StringUtil;

import java.util.regex.Pattern;

/**
 * 
 * @author changbo
 *
 */
public class PasswordUtil {

	private static final Pattern[] PATTERN_LIST = new Pattern[]{
			Pattern.compile("^.*[0-9]+.*$"),
			Pattern.compile("^.*[a-z]+.*$"),
			Pattern.compile("^.*[A-Z]+.*$"),
			Pattern.compile("^.*[\\x21-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7e]+.*$")
	};

	/**
	 */
	public static int level(String password) {
		if(StringUtil.isEmpty(password)) {
			return 0;
		}
		int level = 0;
		for(Pattern pattern : PATTERN_LIST){
			if(pattern.matcher(password).matches()) {
				level++;
			}
		}
		return level ;
	}

}
